package com.neiquan.backstage.resourec_manage.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.pub.bsc.dao.po.Lease;
import com.neiquan.backstage.resourec_manage.ResourecLeaseService;

@Service
public class ResourecLeaseServiceImp implements ResourecLeaseService{
	private static Class<?> poc = Lease.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	
	@Override
	public Lease queryByUniqueId(int memberId,String uniqueId) {
		// TODO Auto-generated method stub
		List<Lease> ListL = (List<Lease>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Lease where memberId=? and unquieId=?", memberId,uniqueId);
		Lease entityL=null;
		if(ListL.size()>0){
			entityL = ListL.get(0);
		}
		return entityL;
	}
	@Override
	public Lease queryByEntrepreneurId(int entrepreneurId, int newlyStuats) {
		// TODO Auto-generated method stub
		List<Lease> listL=  (List<Lease>) extraSpringHibernateTemplate
				.getHibernateTemplate().find("From Lease where entrepreneurId=? and newlyStuats=?", entrepreneurId,newlyStuats);
		if(listL.size()>0){
			return listL.get(0);
		}
		  return null;
	}
	
	@Override
	public List<Lease> queryByMeberId(int memberId, int newlyStuats,int status) {
		// TODO Auto-generated method stub
		return  (List<Lease>) extraSpringHibernateTemplate
				.getHibernateTemplate().find("From Lease where memberId=? and newlyStuats=? and status=?", memberId,newlyStuats,status);
	}
	
	@Override
	public List<Lease> queryByEntrepreneurId(int entrepreneurId) {
		// TODO Auto-generated method stub
		List<Lease> listL=  (List<Lease>) extraSpringHibernateTemplate
				.getHibernateTemplate().find("From Lease where entrepreneurId=?", entrepreneurId);
		if(listL.size()<=0){
			return null;
		}
		  return listL;
	}
	/**
	 * -1表示不加此条件
	 */
	@Override
	public List<Lease> queryByEntrepreneurId(int entrepreneurId, int newlyStuats,int status) {
		// TODO Auto-generated method stub
		List<Lease> listL=null;
		if(status==-1&&newlyStuats==-1){
			listL= (List<Lease>) extraSpringHibernateTemplate
					.getHibernateTemplate().find("From Lease where entrepreneurId=? and status=?", entrepreneurId,status);
		}
		if(status==-1&&newlyStuats!=-1){
			listL= (List<Lease>) extraSpringHibernateTemplate
					.getHibernateTemplate().find("From Lease where entrepreneurId=? and newlyStuats=? ", entrepreneurId,newlyStuats);
		}
		if(status!=-1&&newlyStuats==-1){
			listL= (List<Lease>) extraSpringHibernateTemplate
					.getHibernateTemplate().find("From Lease where entrepreneurId=?", entrepreneurId);
		}
		if(status!=-1&&newlyStuats!=-1){
			listL= (List<Lease>) extraSpringHibernateTemplate
					.getHibernateTemplate().find("From Lease where entrepreneurId=? and newlyStuats=? and status=?", entrepreneurId,newlyStuats,status);
		}
		  return listL;
	}
	@Override
	public void add(Lease entity) {
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}
	@Override
	public Lease queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "leaseId", id);
	}
	@Override
	public void updata(Lease entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(entity);
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Lease> queryAll() {
		// TODO Auto-generated method stub
		return (List<Lease>) extraSpringHibernateTemplate.findAll(poc);
	}
	
	@Override
	public List<Lease> queryByUserId(Integer userId, Integer memberId) {
		// TODO Auto-generated method stub
		return (List<Lease>) extraSpringHibernateTemplate
				.getHibernateTemplate()
				.find("From Lease where userId=? and memberId=?", userId,memberId);
	}

}
